package com.example.demo.service.Impl;

import com.example.demo.entity.Company;
import com.example.demo.entity.CompanyExample;
import com.example.demo.entity.CompanyMember;
import com.example.demo.entity.CompanyMemberExample;
import com.example.demo.mapper.CompanyMapper;
import com.example.demo.mapper.CompanyMemberMapper;
import com.example.demo.service.CompanyMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompanyMemberServiceImpl implements CompanyMemberService {
    @Autowired
    CompanyMemberMapper userMapper;

    @Autowired
    CompanyMapper companyMapper;

    @Override
    public List<Company> getUserCompany(int userId) {
        CompanyMemberExample companymemberexample = new CompanyMemberExample();

        CompanyMemberExample.Criteria criteria = companymemberexample.createCriteria();
        criteria.andCompanyUserIdEqualTo(userId);
        List<CompanyMember> list = userMapper.selectByExample(companymemberexample);
        System.out.println(list);
        List<Integer> companyIds = new ArrayList<>();

        for (int i = 0;i <list.size();i++){
            companyIds.add(list.get(i).getCompanyCompId());
            System.out.println(companyIds.get(i));
        }
        CompanyExample companyExample = new CompanyExample();

        CompanyExample.Criteria criteria1 = companyExample.createCriteria();
        criteria1.andCompanyIdIn(companyIds);
        List<Company> companies = companyMapper.selectByExample(companyExample);
        System.out.println(companies);
        return companies;
    }

}
